Show code
pacman::p_load(arrow, lubridate, sf, tidyverse, spNetwork, tmap,
spatstat, raster, maptools)February 7, 2024
We will be applying appropriate spatial point patterns analysis methods learned in class to discover the geographical and spatio-temporal distribution of Grab hailing services locations in Singapore.
The R packages that we will be using in this exercise are as follows:
arrow: For reading parquet files (Grab-Posisi Dataset)
lubridate: To handle the date formatting
sf: Import, manage and process vector-based geospatial data in R.
tidyverse: a collection of packages for data science tasks
spatstat: Wide range of useful functions for point pattern analysis and derive kernel density estimation (KDE) layer.
spNetwork: provides functions to perform Spatial Point Patterns Analysis such as kernel density estimation (KDE) and K-function on network. It also can be used to build spatial matrices (‘listw’ objects like in ‘spdep’ package) to conduct any kind of traditional spatial analysis with spatial weights based on reticular distances.
tmap: Provides functions for plotting cartographic quality static point patterns maps or interactive maps by using leaflet API.
raster: reads, writes, manipulates, analyses and model of gridded spatial data (i.e. raster). In this hands-on exercise, it will be used to convert image output generate by spatstat into raster format.
maptools: Provides a set of tools for manipulating geographic data. In this take-home exercise, we mainly use it to convert Spatial objects into ppp format of spatstat.
# classInt, viridis, rgdal
The datasets that we will be using are as follow:
Using read_parquet() function from arrow package to import the grab data, then changing pingtimestamp column to datetime object
grab_df0 <- read_parquet("data/aspatial/part-00000.snappy.parquet")
grab_df1 <- read_parquet("data/aspatial/part-00001.snappy.parquet")
grab_df2 <- read_parquet("data/aspatial/part-00002.snappy.parquet")
grab_df3 <- read_parquet("data/aspatial/part-00003.snappy.parquet")
grab_df4 <- read_parquet("data/aspatial/part-00004.snappy.parquet")
grab_df5 <- read_parquet("data/aspatial/part-00005.snappy.parquet")
grab_df6 <- read_parquet("data/aspatial/part-00006.snappy.parquet")
grab_df7 <- read_parquet("data/aspatial/part-00007.snappy.parquet")
grab_df8 <- read_parquet("data/aspatial/part-00008.snappy.parquet")
grab_df9 <- read_parquet("data/aspatial/part-00009.snappy.parquet")Transforming the coordinate system at the same time when we are importing the data
Reading layer `gis_osm_roads_free_1' from data source
`/Users/jacksontan/Documents/Sashimii0219/IS415-GAA/Take-home_Ex/Take-home_Ex01/data/geospatial'
using driver `ESRI Shapefile'
Simple feature collection with 1759836 features and 10 fields
Geometry type: LINESTRING
Dimension: XY
Bounding box: xmin: 99.66041 ymin: 0.8021131 xmax: 119.2601 ymax: 7.514393
Geodetic CRS: WGS 84
Transforming the coordinate system at the same time when we are importing the data
Reading layer `MPSZ-2019' from data source
`/Users/jacksontan/Documents/Sashimii0219/IS415-GAA/Take-home_Ex/Take-home_Ex01/data/geospatial'
using driver `ESRI Shapefile'
Simple feature collection with 332 features and 6 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 103.6057 ymin: 1.158699 xmax: 104.0885 ymax: 1.470775
Geodetic CRS: WGS 84
Before we begin exploring the data, we will first need to perform some data pre-processing on the datasets that we have imported.
As grab won’t be able to reach offshore places, we will exclude the outer islands from this dataset. We will do this through the following steps:
We will first take a look at the unique planning areas in Singapore using unique() on the PLN_AREA_N column of mpsz2019 dataset.
[1] "MARINA EAST" "RIVER VALLEY"
[3] "SINGAPORE RIVER" "WESTERN ISLANDS"
[5] "MUSEUM" "MARINE PARADE"
[7] "SOUTHERN ISLANDS" "BUKIT MERAH"
[9] "DOWNTOWN CORE" "STRAITS VIEW"
[11] "QUEENSTOWN" "OUTRAM"
[13] "MARINA SOUTH" "ROCHOR"
[15] "KALLANG" "TANGLIN"
[17] "NEWTON" "CLEMENTI"
[19] "BEDOK" "PIONEER"
[21] "JURONG EAST" "ORCHARD"
[23] "GEYLANG" "BOON LAY"
[25] "BUKIT TIMAH" "NOVENA"
[27] "TOA PAYOH" "TUAS"
[29] "JURONG WEST" "SERANGOON"
[31] "BISHAN" "TAMPINES"
[33] "BUKIT BATOK" "HOUGANG"
[35] "CHANGI BAY" "PAYA LEBAR"
[37] "ANG MO KIO" "PASIR RIS"
[39] "BUKIT PANJANG" "TENGAH"
[41] "SELETAR" "SUNGEI KADUT"
[43] "YISHUN" "MANDAI"
[45] "PUNGGOL" "CHOA CHU KANG"
[47] "SENGKANG" "CHANGI"
[49] "CENTRAL WATER CATCHMENT" "SEMBAWANG"
[51] "WESTERN WATER CATCHMENT" "WOODLANDS"
[53] "NORTH-EASTERN ISLANDS" "SIMPANG"
[55] "LIM CHU KANG"

Note that there are 3 areas with island in their name, mainly “NORTH-EASTERN ISLANDS”, “SOUTHERN ISLANDS”, and “WESTERN ISLANDS”.
To exclude the islands, we simply have to pass a condition to exclude these islands in the subset function.
We will be using the st_is_valid() function to test for invalid geometries.
[1] 3
[1] "Ring Self-intersection[26922.5243000389 27027.610899987]"
[2] "Ring Self-intersection[38991.2589000446 31986.5599999869]"
[3] "Ring Self-intersection[14484.6860000313 31330.1319999856]"
We can see that there are 3 invalid geometries. Let’s fix them using st_make_valid().
Simple feature collection with 0 features and 6 fields
Bounding box: xmin: NA ymin: NA xmax: NA ymax: NA
Projected CRS: SVY21 / Singapore TM
[1] SUBZONE_N SUBZONE_C PLN_AREA_N PLN_AREA_C REGION_N REGION_C geometry
<0 rows> (or 0-length row.names)
Using the code above, we can see that there are no missing values.
As the dataset contains data from Malaysia and Brunei as well, we will use st_intersection() to limit the data to only Singapore.
Now, we can see that in points_within_sg it only contain Singapore road data, combined with the other values from mpsz2019 like “PLN_AREA_N” used above.
[1] "osm_id" "code" "fclass" "name" "ref"
[6] "oneway" "maxspeed" "layer" "bridge" "tunnel"
[11] "SUBZONE_N" "SUBZONE_C" "PLN_AREA_N" "PLN_AREA_C" "REGION_N"
[16] "REGION_C" "geometry"
Simple feature collection with 6 features and 16 fields
Geometry type: LINESTRING
Dimension: XY
Bounding box: xmin: 31466.72 ymin: 30680.54 xmax: 32815.21 ymax: 30873.74
Projected CRS: SVY21 / Singapore TM
osm_id code fclass name ref oneway maxspeed layer
4052 23946437 5122 residential Rhu Cross <NA> F 50 0
9668 32605139 5131 motorway_link <NA> <NA> F 40 0
20076 46337834 5131 motorway_link <NA> <NA> F 50 -2
21690 49961799 5111 motorway East Coast Parkway ECP F 70 1
26543 74722808 5111 motorway East Coast Parkway ECP F 70 1
29808 99007260 5131 motorway_link <NA> <NA> F 50 1
bridge tunnel SUBZONE_N SUBZONE_C PLN_AREA_N PLN_AREA_C REGION_N
4052 F F MARINA EAST MESZ01 MARINA EAST ME CENTRAL REGION
9668 F F MARINA EAST MESZ01 MARINA EAST ME CENTRAL REGION
20076 F T MARINA EAST MESZ01 MARINA EAST ME CENTRAL REGION
21690 F F MARINA EAST MESZ01 MARINA EAST ME CENTRAL REGION
26543 T F MARINA EAST MESZ01 MARINA EAST ME CENTRAL REGION
29808 T F MARINA EAST MESZ01 MARINA EAST ME CENTRAL REGION
REGION_C geometry
4052 CR LINESTRING (31889.45 30760....
9668 CR LINESTRING (32768.57 30857....
20076 CR LINESTRING (32815.21 30873....
21690 CR LINESTRING (32365.45 30845....
26543 CR LINESTRING (31611.63 30720....
29808 CR LINESTRING (31611.63 30720....
Again, using the st_is_valid() function to test for invalid geometries.
[1] 0
character(0)
No invalid geometries!
Simple feature collection with 232766 features and 16 fields
Geometry type: GEOMETRY
Dimension: XY
Bounding box: xmin: 2679.373 ymin: 23099.51 xmax: 50957.8 ymax: 50220.06
Projected CRS: SVY21 / Singapore TM
First 10 features:
osm_id code fclass name ref oneway maxspeed layer
4052 23946437 5122 residential Rhu Cross <NA> F 50 0
9668 32605139 5131 motorway_link <NA> <NA> F 40 0
20076 46337834 5131 motorway_link <NA> <NA> F 50 -2
29808 99007260 5131 motorway_link <NA> <NA> F 50 1
45723 140562813 5131 motorway_link <NA> <NA> F 70 -1
45728 140562819 5131 motorway_link <NA> <NA> F 50 0
45731 140562823 5131 motorway_link <NA> <NA> F 60 -2
45733 140562826 5131 motorway_link <NA> <NA> F 40 0
52966 150819034 5141 service Bay East Drive <NA> B 0 0
84664 174717984 5153 footway <NA> <NA> B 0 0
bridge tunnel SUBZONE_N SUBZONE_C PLN_AREA_N PLN_AREA_C REGION_N
4052 F F MARINA EAST MESZ01 MARINA EAST ME CENTRAL REGION
9668 F F MARINA EAST MESZ01 MARINA EAST ME CENTRAL REGION
20076 F T MARINA EAST MESZ01 MARINA EAST ME CENTRAL REGION
29808 T F MARINA EAST MESZ01 MARINA EAST ME CENTRAL REGION
45723 F F MARINA EAST MESZ01 MARINA EAST ME CENTRAL REGION
45728 F F MARINA EAST MESZ01 MARINA EAST ME CENTRAL REGION
45731 F T MARINA EAST MESZ01 MARINA EAST ME CENTRAL REGION
45733 F F MARINA EAST MESZ01 MARINA EAST ME CENTRAL REGION
52966 F F MARINA EAST MESZ01 MARINA EAST ME CENTRAL REGION
84664 F F MARINA EAST MESZ01 MARINA EAST ME CENTRAL REGION
REGION_C geometry
4052 CR LINESTRING (31889.45 30760....
9668 CR LINESTRING (32768.57 30857....
20076 CR LINESTRING (32815.21 30873....
29808 CR LINESTRING (31611.63 30720....
45723 CR LINESTRING (32782.42 30754....
45728 CR LINESTRING (32645.37 30683....
45731 CR LINESTRING (32809.68 30108....
45733 CR LINESTRING (32609.11 30700....
52966 CR LINESTRING (32173.46 30036....
84664 CR LINESTRING (31750.06 30644....
By using the code above, we can see that majority of the missing values are in the ‘name’ and ‘ref’ column. Therefore, let’s drop the irrelevant columns first before we try it again!
We only kept “osm_id”, “code”, “fclass”, and “PLN_AREA_N” columns.
Simple feature collection with 0 features and 4 fields
Bounding box: xmin: NA ymin: NA xmax: NA ymax: NA
Projected CRS: SVY21 / Singapore TM
[1] osm_id code fclass PLN_AREA_N geometry
<0 rows> (or 0-length row.names)
No more missing values here.
Our map so far:
The Grab-Posisi Dataset is an Aspatial dataset, different from the two we prepared above. As such, the pre-processing is slightly different too.
The code below is a chain of dplyr pipes to group the trips by their id and extract the first pingtimestamp row of each trip in order to get the origin of it.
We will need the files in SF format first before we can use it for further geospatial analysis.
Simple feature collection with 0 features and 10 fields
Bounding box: xmin: NA ymin: NA xmax: NA ymax: NA
Projected CRS: SVY21 / Singapore TM
# A tibble: 0 × 11
# Groups: trj_id [0]
# ℹ 11 variables: trj_id <chr>, driving_mode <chr>, osname <chr>,
# pingtimestamp <dttm>, speed <dbl>, bearing <int>, accuracy <dbl>,
# weekday <ord>, start_hr <fct>, day <fct>, geometry <GEOMETRY [m]>
Simple feature collection with 0 features and 10 fields
Bounding box: xmin: NA ymin: NA xmax: NA ymax: NA
Projected CRS: SVY21 / Singapore TM
# A tibble: 0 × 11
# Groups: trj_id [0]
# ℹ 11 variables: trj_id <chr>, driving_mode <chr>, osname <chr>,
# pingtimestamp <dttm>, speed <dbl>, bearing <int>, accuracy <dbl>,
# weekday <ord>, end_hr <fct>, day <fct>, geometry <GEOMETRY [m]>
No missing values, we are almost ready.
To verify that the points that we removed is indeed from the islands, here’s a chunk of code to prove:
# Finding out points removed
diff_id <- origin_sf$trj_id[!(origin_sf$trj_id %in% origin_sf_new$trj_id)]
# Extracting full information of these points
outliers <- origin_sf[(origin_sf$trj_id %in% diff_id), ]
# Checking where these places are from
unique(st_intersection(outliers, mpsz2019)$PLN_AREA_N)[1] "WESTERN ISLANDS" "SOUTHERN ISLANDS"
They are indeed from “WESTERN ISLANDS” and “SOUTHERN ISLANDS”.
Now that our grab dataset is almost ready, we need to decide which column we should drop. Here are the columns in both origin_sf_new and dest_sf_new:
[1] "trj_id" "driving_mode" "osname" "pingtimestamp"
[5] "speed" "bearing" "accuracy" "weekday"
[9] "start_hr" "day" "SUBZONE_N" "SUBZONE_C"
[13] "PLN_AREA_N" "PLN_AREA_C" "REGION_N" "REGION_C"
[17] "geometry"
[1] "trj_id" "driving_mode" "osname" "pingtimestamp"
[5] "speed" "bearing" "accuracy" "weekday"
[9] "end_hr" "day" "SUBZONE_N" "SUBZONE_C"
[13] "PLN_AREA_N" "PLN_AREA_C" "REGION_N" "REGION_C"
[17] "geometry"
We will definitely be dropping the columns merged from mpsz2019_new (other than PLN_AREA_N), but what about “driving_mode”, “osname”, “speed”, “bearing”, and “accuracy”? Let’s first take a look at them.
Seeing that there is only 1 constant in the column, it is safe for us to drop this column.
There are 2 values, mainly “ios” and “android”. Arguments can be made that we can analyse the behavior of both type in terms of using grab hailing services, but that’s not what we will doing so we will drop this as well.
As we are analysing start/stop points, speed will not be a relevant factor hence we will be dropping them.
Not relevant as well, hence dropping.
According to research paper published on Grab website, this is the definition of the accuracy column:
“…the accuracy level roughly indicates the radius of the circle within which the true location lies with a certain probability. The lower the accuracy level, the more precise the reported GPS ping is.”
With that, let’s take a look at the distribution of accuracy score.


From the plot, we can see that there are 3 clear outliers with accuracy above 180~ for origin_sf_new, and 1 for dest_sf_new. Now let’s extract these trips.
Simple feature collection with 1 feature and 16 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 29008.44 ymin: 32353.78 xmax: 29008.44 ymax: 32353.78
Projected CRS: SVY21 / Singapore TM
# A tibble: 1 × 17
trj_id driving_mode osname pingtimestamp speed bearing accuracy weekday
<chr> <chr> <chr> <dttm> <dbl> <int> <dbl> <ord>
1 59560 car ios 2019-04-16 00:28:59 -1 26 728 Tue
# ℹ 9 more variables: start_hr <fct>, day <fct>, SUBZONE_N <chr>,
# SUBZONE_C <chr>, PLN_AREA_N <chr>, PLN_AREA_C <chr>, REGION_N <chr>,
# REGION_C <chr>, geometry <POINT [m]>
Simple feature collection with 7 features and 16 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 28983.51 ymin: 29952.1 xmax: 33721.09 ymax: 34502.5
Projected CRS: SVY21 / Singapore TM
# A tibble: 7 × 17
trj_id driving_mode osname pingtimestamp speed bearing accuracy weekday
<chr> <chr> <chr> <dttm> <dbl> <int> <dbl> <ord>
1 54788 car ios 2019-04-09 11:06:56 -1 203 1414 Tue
2 14443 car ios 2019-04-11 01:09:18 -1 223 1414 Thu
3 36434 car ios 2019-04-18 07:41:35 -1 126 806 Thu
4 60701 car ios 2019-04-13 03:16:02 -1 130 818 Sat
5 24103 car ios 2019-04-11 13:19:30 -1 117 1402 Thu
6 58922 car ios 2019-04-13 15:50:44 -1 31 1414 Sat
7 68340 car ios 2019-04-12 11:55:48 -1 10 1414 Fri
# ℹ 9 more variables: end_hr <fct>, day <fct>, SUBZONE_N <chr>,
# SUBZONE_C <chr>, PLN_AREA_N <chr>, PLN_AREA_C <chr>, REGION_N <chr>,
# REGION_C <chr>, geometry <POINT [m]>
To ensure that our data is of utmost accuracy, we will drop these trips, before we drop the accuracy column as well (as we will not need it anymore).
With that done, we can now drop the columns that we don’t need.
Lastly, let’s check for duplicated points on the map.
[1] FALSE
[1] 0
No duplicated points!
It is important for the data to be in the right coordinate reference system (CRS). In this assignment, all spatial data will be projected in EPSG:3414, which is a projected coordinate system for Singapore.
Coordinate Reference System:
User input: EPSG:3414
wkt:
PROJCRS["SVY21 / Singapore TM",
BASEGEOGCRS["SVY21",
DATUM["SVY21",
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
ID["EPSG",4757]],
CONVERSION["Singapore Transverse Mercator",
METHOD["Transverse Mercator",
ID["EPSG",9807]],
PARAMETER["Latitude of natural origin",1.36666666666667,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8801]],
PARAMETER["Longitude of natural origin",103.833333333333,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8802]],
PARAMETER["Scale factor at natural origin",1,
SCALEUNIT["unity",1],
ID["EPSG",8805]],
PARAMETER["False easting",28001.642,
LENGTHUNIT["metre",1],
ID["EPSG",8806]],
PARAMETER["False northing",38744.572,
LENGTHUNIT["metre",1],
ID["EPSG",8807]]],
CS[Cartesian,2],
AXIS["northing (N)",north,
ORDER[1],
LENGTHUNIT["metre",1]],
AXIS["easting (E)",east,
ORDER[2],
LENGTHUNIT["metre",1]],
USAGE[
SCOPE["Cadastre, engineering survey, topographic mapping."],
AREA["Singapore - onshore and offshore."],
BBOX[1.13,103.59,1.47,104.07]],
ID["EPSG",3414]]
Coordinate Reference System:
User input: EPSG:3414
wkt:
PROJCRS["SVY21 / Singapore TM",
BASEGEOGCRS["SVY21",
DATUM["SVY21",
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
ID["EPSG",4757]],
CONVERSION["Singapore Transverse Mercator",
METHOD["Transverse Mercator",
ID["EPSG",9807]],
PARAMETER["Latitude of natural origin",1.36666666666667,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8801]],
PARAMETER["Longitude of natural origin",103.833333333333,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8802]],
PARAMETER["Scale factor at natural origin",1,
SCALEUNIT["unity",1],
ID["EPSG",8805]],
PARAMETER["False easting",28001.642,
LENGTHUNIT["metre",1],
ID["EPSG",8806]],
PARAMETER["False northing",38744.572,
LENGTHUNIT["metre",1],
ID["EPSG",8807]]],
CS[Cartesian,2],
AXIS["northing (N)",north,
ORDER[1],
LENGTHUNIT["metre",1]],
AXIS["easting (E)",east,
ORDER[2],
LENGTHUNIT["metre",1]],
USAGE[
SCOPE["Cadastre, engineering survey, topographic mapping."],
AREA["Singapore - onshore and offshore."],
BBOX[1.13,103.59,1.47,104.07]],
ID["EPSG",3414]]
Coordinate Reference System:
User input: EPSG:3414
wkt:
PROJCRS["SVY21 / Singapore TM",
BASEGEOGCRS["SVY21",
DATUM["SVY21",
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
ID["EPSG",4757]],
CONVERSION["Singapore Transverse Mercator",
METHOD["Transverse Mercator",
ID["EPSG",9807]],
PARAMETER["Latitude of natural origin",1.36666666666667,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8801]],
PARAMETER["Longitude of natural origin",103.833333333333,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8802]],
PARAMETER["Scale factor at natural origin",1,
SCALEUNIT["unity",1],
ID["EPSG",8805]],
PARAMETER["False easting",28001.642,
LENGTHUNIT["metre",1],
ID["EPSG",8806]],
PARAMETER["False northing",38744.572,
LENGTHUNIT["metre",1],
ID["EPSG",8807]]],
CS[Cartesian,2],
AXIS["northing (N)",north,
ORDER[1],
LENGTHUNIT["metre",1]],
AXIS["easting (E)",east,
ORDER[2],
LENGTHUNIT["metre",1]],
USAGE[
SCOPE["Cadastre, engineering survey, topographic mapping."],
AREA["Singapore - onshore and offshore."],
BBOX[1.13,103.59,1.47,104.07]],
ID["EPSG",3414]]
Coordinate Reference System:
User input: EPSG:3414
wkt:
PROJCRS["SVY21 / Singapore TM",
BASEGEOGCRS["SVY21",
DATUM["SVY21",
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
ID["EPSG",4757]],
CONVERSION["Singapore Transverse Mercator",
METHOD["Transverse Mercator",
ID["EPSG",9807]],
PARAMETER["Latitude of natural origin",1.36666666666667,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8801]],
PARAMETER["Longitude of natural origin",103.833333333333,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8802]],
PARAMETER["Scale factor at natural origin",1,
SCALEUNIT["unity",1],
ID["EPSG",8805]],
PARAMETER["False easting",28001.642,
LENGTHUNIT["metre",1],
ID["EPSG",8806]],
PARAMETER["False northing",38744.572,
LENGTHUNIT["metre",1],
ID["EPSG",8807]]],
CS[Cartesian,2],
AXIS["northing (N)",north,
ORDER[1],
LENGTHUNIT["metre",1]],
AXIS["easting (E)",east,
ORDER[2],
LENGTHUNIT["metre",1]],
USAGE[
SCOPE["Cadastre, engineering survey, topographic mapping."],
AREA["Singapore - onshore and offshore."],
BBOX[1.13,103.59,1.47,104.07]],
ID["EPSG",3414]]
They are all in the correct CRS!
Finally, plotting all three datasets together to ensure that they have a consistent projection system.
Before we begin our Geospatial Analysis, let’s first take a closer look at the Grab dataset.
The distribution of the trips across all 7 days of the week looks even.
First let us look at the top 10 planning areas for grab ride origin points. Tampines is the Planning Area with the most origin points.
origin_pl_area <- origin_sf_new %>%
group_by(PLN_AREA_N) %>%
summarise(total_count=n()) %>%
top_n(10, total_count) %>%
.$PLN_AREA_N
ggplot(origin_sf_new[origin_sf_new$PLN_AREA_N %in% origin_pl_area,],
aes(x=PLN_AREA_N)) + geom_bar() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +
labs(title = "Trips Origin Distribution by Planning Area",
x = "Planning Area",
y = "Number of Trips")
Then for the destination points.
dest_pl_area <- dest_sf_new %>%
group_by(PLN_AREA_N) %>%
summarise(total_count=n()) %>%
top_n(10, total_count) %>%
.$PLN_AREA_N
ggplot(dest_sf_new[dest_sf_new$PLN_AREA_N %in% dest_pl_area,],
aes(x=PLN_AREA_N)) + geom_bar() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +
labs(title = "Trips Destination Distribution by Planning Area",
x = "Planning Area",
y = "Number of Trips")
6 out of 10 of the Planning Areas remains the same for destination points, mainly TAMPINES, WOODLANDS, YISHUN, QUEENSTOWN, BUKIT MERAH, and CHANGI. This time however, the Planning Area with the most destination points is Changi.

From the graph, we can see that the starting hour peaks at midnight (12am - 1am) and morning (9am - 10am), the former probably due to the lack of public transport after operating hours, and the latter from rush hour.
In the code chunk below, as.ppp() function is used to derive a ppp object layer directly from a sf tibble data.frame.
Marked planar point pattern: 27871 points
Average intensity 2.631202e-05 points per square unit
Coordinates are given to 3 decimal places
i.e. rounded to the nearest multiple of 0.001 units
marks are of type 'character'
Summary:
Length Class Mode
27871 character character
Window: rectangle = [3628.24, 49845.23] x [26770.58, 49689.64] units
(46220 x 22920 units)
Window area = 1059250000 square units
Marked planar point pattern: 27811 points
Average intensity 2.645533e-05 points per square unit
Coordinates are given to 3 decimal places
i.e. rounded to the nearest multiple of 0.001 units
marks are of type 'character'
Summary:
Length Class Mode
27811 character character
Window: rectangle = [3637.21, 49870.63] x [26770.04, 49507.79] units
(46230 x 22740 units)
Window area = 1051240000 square units
In the code chunk as.owin() is used to create an owin object class from polygon sf tibble data.frame. In this case, we will be converting the sg_boundary polygon.
We will now combine singapore’s boundary and the origin and destination points into one.
Marked planar point pattern: 27811 points
Average intensity 4.184642e-05 points per square unit
Coordinates are given to 3 decimal places
i.e. rounded to the nearest multiple of 0.001 units
marks are of type 'character'
Summary:
Length Class Mode
27811 character character
Window: polygonal boundary
37 separate polygons (29 holes)
vertices area relative.area
polygon 1 12666 6.63014e+08 9.98e-01
polygon 2 285 1.61128e+06 2.42e-03
polygon 3 27 1.50315e+04 2.26e-05
polygon 4 (hole) 41 -4.01660e+04 -6.04e-05
polygon 5 (hole) 317 -5.11280e+04 -7.69e-05
polygon 6 (hole) 3 -4.14099e-04 -6.23e-13
polygon 7 30 2.80002e+04 4.21e-05
polygon 8 (hole) 4 -2.86396e-01 -4.31e-10
polygon 9 (hole) 3 -1.81439e-04 -2.73e-13
polygon 10 (hole) 3 -8.68789e-04 -1.31e-12
polygon 11 (hole) 3 -5.99535e-04 -9.02e-13
polygon 12 (hole) 3 -3.04561e-04 -4.58e-13
polygon 13 (hole) 3 -4.46076e-04 -6.71e-13
polygon 14 (hole) 3 -3.39794e-04 -5.11e-13
polygon 15 (hole) 3 -4.52043e-05 -6.80e-14
polygon 16 (hole) 3 -3.90173e-05 -5.87e-14
polygon 17 (hole) 3 -9.59850e-05 -1.44e-13
polygon 18 (hole) 4 -2.54488e-04 -3.83e-13
polygon 19 (hole) 4 -4.28453e-01 -6.45e-10
polygon 20 (hole) 4 -2.18616e-04 -3.29e-13
polygon 21 (hole) 5 -2.44411e-04 -3.68e-13
polygon 22 (hole) 5 -3.64686e-02 -5.49e-11
polygon 23 71 8.18750e+03 1.23e-05
polygon 24 (hole) 6 -8.37554e-01 -1.26e-09
polygon 25 (hole) 38 -7.79904e+03 -1.17e-05
polygon 26 (hole) 3 -3.41897e-05 -5.14e-14
polygon 27 (hole) 3 -3.65499e-03 -5.50e-12
polygon 28 (hole) 3 -4.95057e-02 -7.45e-11
polygon 29 91 1.49663e+04 2.25e-05
polygon 30 (hole) 5 -2.92235e-04 -4.40e-13
polygon 31 (hole) 3 -7.43616e-06 -1.12e-14
polygon 32 (hole) 270 -1.21455e+03 -1.83e-06
polygon 33 (hole) 19 -4.39650e+00 -6.62e-09
polygon 34 (hole) 35 -1.38385e+02 -2.08e-07
polygon 35 (hole) 23 -1.99656e+01 -3.00e-08
polygon 36 71 5.63061e+03 8.47e-06
polygon 37 10 1.99717e+02 3.01e-07
enclosing rectangle: [2667.54, 55941.94] x [21448.47, 50256.33] units
(53270 x 28810 units)
Window area = 664597000 square units
Fraction of frame area: 0.433
The density values of the output range from 0 to 0.000035 which is way too small to comprehend, and it is computed in “number of points per square meter”. Therefore, we are going to use rescale() to covert the unit of measurement from meter to kilometer.
We will first compute the kernel density by using density() of the spatstat package, with the default method bw.diggle().

Looking at all the different methods, we can see that bw.diggle() is still the best among the automatic bandwidth selection method.
Having tried automatic bandwidth selection method, let’s try computing KDE by using a fixed bandwidth defined by us. In our case, we will define a fixed bandwidth of 800m (or 0.8km).
Fixed bandwidth method, however, is very sensitive to highly skewed distribution of spatial point patterns over geographical units, for example urban versus rural. To overcome this, we can try using adaptive bandwidth instead.
As the KDE layer using fixed bandwidth with gaussian kernel plots a graph that allows for meaningful analysis at a glance, we will be using that for the steps moving forward.



In order for us to map the KDE layer of these points to our map, we first need to convert it into grid object.
We will then convert the gridded kernel density objects into RasterLayer object by using raster() of raster package. As the RasterLayer object does not include CRS information, we will need to manually assign it to them as well.
class : RasterLayer
dimensions : 128, 128, 16384 (nrow, ncol, ncell)
resolution : 0.4162063, 0.2250614 (x, y)
extent : 2.667538, 55.94194, 21.44847, 50.25633 (xmin, xmax, ymin, ymax)
crs : +proj=tmerc +lat_0=1.36666666666667 +lon_0=103.833333333333 +k=1 +x_0=28001.642 +y_0=38744.572 +datum=WGS84 +units=km +no_defs
source : memory
names : v
values : -1.552973e-14, 591.2389 (min, max)
class : RasterLayer
dimensions : 128, 128, 16384 (nrow, ncol, ncell)
resolution : 0.4162063, 0.2250614 (x, y)
extent : 2.667538, 55.94194, 21.44847, 50.25633 (xmin, xmax, ymin, ymax)
crs : +proj=tmerc +lat_0=1.36666666666667 +lon_0=103.833333333333 +k=1 +x_0=28001.642 +y_0=38744.572 +datum=WGS84 +units=km +no_defs
source : memory
names : v
values : -1.361913e-14, 526.6182 (min, max)
To further explore the map, we will now be overlaying the KDE layer both onto OpenStreetMap of Singapore, and also on the Singapore Planning Area layer and OSM road layer that we have pre-processed.
As you can see from the plot, there are certain planning areas that are hotspots for hailing of Grab ride service, in particular Central Region (Orchard, Newton etc), Woodlands, Punggol, Tampines, and most notably Changi (where the airport lies).
To further confirm our observation, let’s plot the KDE layer over our Planning Area and OSM Road Layers.
The common overlapping Planning Areas include “TAMPINES”, “CHANGI”, “WOODLANDS”, and “NOVENA”, so let’s do a further analysis on these areas.
To do in-depth KDE computation on these 4 planning areas, we will first need to extract their respective boundaries. In the code below, we extracted their boundaries and converted them to sp’s Spatial* class.
Plotting down these boundaries.

Turning the spatial point data frame into generic sp format, then into owin object as done previously.
By using the code below, we will be able to extract grab origin and destination points for these specific areas.
Next up is the rescale() function used previously as well.
origin_cg_ppp.km = rescale(origin_cg_ppp, 1000, "km")
origin_tp_ppp.km = rescale(origin_tp_ppp, 1000, "km")
origin_wl_ppp.km = rescale(origin_wl_ppp, 1000, "km")
origin_nv_ppp.km = rescale(origin_nv_ppp, 1000, "km")
dest_cg_ppp.km = rescale(dest_cg_ppp, 1000, "km")
dest_tp_ppp.km = rescale(dest_tp_ppp, 1000, "km")
dest_wl_ppp.km = rescale(dest_wl_ppp, 1000, "km")
dest_nv_ppp.km = rescale(dest_nv_ppp, 1000, "km")Finally, we plot the four planning areas and the grab hailing origin and destination points
par(mfrow=c(2,4))
plot(origin_cg_ppp.km, main = "CHANGI ORIGIN")
plot(origin_tp_ppp.km, main = "TAMPINES ORIGIN")
plot(origin_wl_ppp.km, main = "WOODLANDS ORIGIN")
plot(origin_nv_ppp.km, main = "NOVENA ORIGIN")
plot(dest_cg_ppp.km, main = "CHANGI DESTINATION")
plot(dest_tp_ppp.km, main = "TAMPINES DESTINATION")
plot(dest_wl_ppp.km, main = "WOODLANDS DESTINATION")
plot(dest_nv_ppp.km, main = "NOVENA DESTINATION")
We will now be computing the KDE of each planning area using the fixed bandwidth method.


The hotspot in Changi area is centered around Changi Airport, indicating a likely surge in use of Grab services due to the constant flow of passengers arriving and departing from Singapore.


The hotspot in Tampines area is mainly concentrated around the stretch from Tampines West to Tampines East, encompassing the bulk of where most residents of Tampines currently live (Tampines West, Tampines, Tampines East).


The rides are concentrated around the lower half of Woodlands area, ranging from Woodlands West to Woodlands South, then Woodlands East. However, one prominent hotspot shared across both the origin and destination map is the Woodlands West region, indicating that this might either be the area with the wealthiest residents in Woodlands, or that there are just more residents concentrated here.


The Novena area’s notable hotspots present an interesting distinction. Origin points predominantly converge around the affluent Moulmein area, revealing a concentration in the wealthier section of town. Conversely, the destination points gravitate towards the Malcolm area, characterized by a cluster of prestigious schools, as illustrated in the figure below.


In this section, we will perform the Clark-Evans test of aggregation for a spatial point pattern by using clarkevans.test() of statspat package, to test whether the distribution of Grab ride hailing origin points are randomly distributed.
Using 95% confidence interval, the test hypotheses are:
Ho = The distribution of Grab ride hailing origin points are randomly distributed.
H1= The distribution of Grab ride hailing origin points are not randomly distributed.
For this section, we will be making use of the ppp object.
Having performed the Clark-Evans Test on all 4 planning area and Singapore as a whole, all of their p-values are <2.2e-16 < 0.05, thus we reject Ho. This means that the distribution of Grab ride hailing origin points are not randomly distributed which we explored in earlier sections.
Furthermore, as their R value ranges from 0.11647 to 0.35838 which is <1, this suggests that the points are clustering.
In this section, we will be using appropriate functions of spNetwork package:
where in this case the network refers to OSM’s Road Map of Singapore.
However, due to limitations in computational power, we will be limiting the area of scope down to the 4 areas identified in the previous section, Changi, Tampines, Woodlands, and Novena, and only the Origin points.
Before we begin, let us first convert our sg_roads_new data from SFC_GEOMETRY to SFC_LINESTRING.
Then, let us narrow down the scope of our data to the 4 areas mentioned.
# Roads
cg_roads <- sg_roads_linestring %>% filter(PLN_AREA_N == "CHANGI")
tp_roads <- sg_roads_linestring %>% filter(PLN_AREA_N == "TAMPINES")
wl_roads <- sg_roads_linestring %>% filter(PLN_AREA_N == "WOODLANDS")
nv_roads <- sg_roads_linestring %>% filter(PLN_AREA_N == "NOVENA")
# Grab Origin Points
cg_origin <- origin_sf_new %>% filter(PLN_AREA_N == "CHANGI")
tp_origin <- origin_sf_new %>% filter(PLN_AREA_N == "TAMPINES")
wl_origin <- origin_sf_new %>% filter(PLN_AREA_N == "WOODLANDS")
nv_origin <- origin_sf_new %>% filter(PLN_AREA_N == "NOVENA")Before we begin our analysis, let us visualise our geospatial data to make sure everything falls into place.
We will now perform NetKDE analysis by using appropriate functions provided in spNetwork package.
Next, we will use lines_center() of spNetwork to generate a SpatialPointsDataFrame (i.e. samples) with line centre points.
We are now ready to compute NetKDE. As the code is fairly long, we will split it into 4 tabs.
# Origin
cg_o_densities <- nkde(cg_roads,
events = cg_origin,
w = rep(1,nrow(cg_origin)),
samples = cg_lines_center,
kernel_name = "quartic", # kernel method
bw = 300,
div= "bw",
method = "simple",
# method used to calculate NKDE. spNetwork supports 3 popular methods, namely simple, discontinuous, and continuous
digits = 1,
tol = 1,
grid_shape = c(1,1),
max_depth = 8,
agg = 5,
# we aggregate events within a 5m radius (faster calculation)
sparse = TRUE,
verbose = FALSE)tp_o_densities <- nkde(tp_roads,
events = tp_origin,
w = rep(1,nrow(tp_origin)),
samples = tp_lines_center,
kernel_name = "quartic", # kernel method
bw = 300,
div= "bw",
method = "simple",
# method used to calculate NKDE. spNetwork supports 3 popular methods, namely simple, discontinuous, and continuous
digits = 1,
tol = 1,
grid_shape = c(1,1),
max_depth = 8,
agg = 5,
# we aggregate events within a 5m radius (faster calculation)
sparse = TRUE,
verbose = FALSE)wl_o_densities <- nkde(wl_roads,
events = wl_origin,
w = rep(1,nrow(wl_origin)),
samples = wl_lines_center,
kernel_name = "quartic", # kernel method
bw = 300,
div= "bw",
method = "simple",
# method used to calculate NKDE. spNetwork supports 3 popular methods, namely simple, discontinuous, and continuous
digits = 1,
tol = 1,
grid_shape = c(1,1),
max_depth = 8,
agg = 5,
# we aggregate events within a 5m radius (faster calculation)
sparse = TRUE,
verbose = FALSE)nv_o_densities <- nkde(nv_roads,
events = nv_origin,
w = rep(1,nrow(nv_origin)),
samples = nv_lines_center,
kernel_name = "quartic", # kernel method
bw = 300,
div= "bw",
method = "simple",
# method used to calculate NKDE. spNetwork supports 3 popular methods, namely simple, discontinuous, and continuous
digits = 1,
tol = 1,
grid_shape = c(1,1),
max_depth = 8,
agg = 5,
# we aggregate events within a 5m radius (faster calculation)
sparse = TRUE,
verbose = FALSE)Before we are able to visualise, we first need to insert the computed values back into lines_center and lixels objects as density field.
cg_lines_center$o_density <- cg_o_densities
cg_lixels$o_density <- cg_o_densities
tp_lines_center$o_density <- tp_o_densities
tp_lixels$o_density <- tp_o_densities
wl_lines_center$o_density <- wl_o_densities
wl_lixels$o_density <- wl_o_densities
nv_lines_center$o_density <- nv_o_densities
nv_lixels$o_density <- nv_o_densitiesSince svy21 projection system is in meter, the computed density values are very small i.e. 0.0000005. We will thus need to rescale the density values from number of events per meter to number of events per kilometer.
cg_lines_center$o_density <- cg_lines_center$o_density*1000
cg_lixels$o_density <- cg_lixels$o_density*1000
tp_lines_center$o_density <- tp_lines_center$o_density*1000
tp_lixels$o_density <- tp_lixels$o_density*1000
wl_lines_center$o_density <- wl_lines_center$o_density*1000
wl_lixels$o_density <- wl_lixels$o_density*1000
nv_lines_center$o_density <- nv_lines_center$o_density*1000
nv_lixels$o_density <- nv_lixels$o_density*1000This tmap plot further reinforces our observation above that the grab ride traffic are from incoming tourists or locals returning home form the airport, as you can see the denser area being the Changi Airport Terminals. However, it is worth highlighting that there some slight traffic along the Changi Village area and infront of the Japanese School as well.
As we have discovered earlier, a huge portion of the grab rides indeed originated from Tampines East, one of the more populated area of Tampines. Particularly along Tampines Avenue 2, there seems to be a higher density, presumably due to it being more convenient to get a ride along the main road.
Surprisingly, the other higher density area in this network density map is the area around Changi General Hospital.
There are 3 main points of to focus on with higher density, mainly:
Along the route to Woodlands Checkpoint, showing that a significant portion of the rides in Woodlands are people coming in from Malaysia.
Around the main hub of Woodlands, along the Woodlands MRT stretch. No surprises here, as the area is perhaps the most dense in terms of human traffic due to concentration of malls, bus interchange, and MRT station.
3 different points around the Sembawang Air Base, which I assume is the entrance. This make sense as well, as military bases in Singapore are generally more inaccessible.
Network KDE indicates that the majority of the traffic is along Moulmein Road, which is the main road next to several of the moderately wealthier estates in Singapore.
We are now going to perform complete spatial randomness (CSR) test by using kfunctions() of spNetwork package. The null hypothesis is defined as:
The CSR test is based on the assumption of the binomial point process which implies the hypothesis that the childcare centres are randomly and independently distributed over the street network.
If this hypothesis is rejected, we may infer that the distribution of Grab ride hailing points are spatially interacting and dependent on each other; as a result, they may form nonrandom patterns.
kfun_cg <- kfunctions(cg_roads,
cg_origin[c("trj_id","PLN_AREA_N", "geometry")],
start = 0,
# A double, the start value for evaluating the k and g functions.
end = 1000,
# A double, the last value for evaluating the k and g functions.
step = 50,
# A double, the jump between two evaluations of the k and g function
width = 50,
# The width of each donut for the g-function
nsim = 50,
# number of Monte Carlo simulations required.
resolution = 50,
verbose = FALSE,
agg = 5,
conf_int = 0.05
# A double indicating the width confidence interval (default = 0.05).
)
kfun_cg$plotk

$plotg

$values
obs_k lower_k upper_k obs_g lower_g upper_g distances
1 0.00000 0.000000 0.000000 14.46260 0.5420546 0.784789 0
2 32.75743 2.342464 2.853884 39.67653 2.7725177 3.382085 50
3 73.63982 5.360448 6.390508 37.85016 3.2858891 4.071459 100
4 112.49292 8.949365 10.697872 42.18582 3.8956518 4.818003 150
5 155.30314 13.283265 15.490119 44.29316 4.5988789 5.638500 200
6 201.05973 18.158245 21.349109 46.36538 5.1842511 6.160652 250
7 249.41538 23.436936 27.795617 48.76931 5.4340099 6.853537 300
8 298.82079 29.534173 34.941060 49.48736 5.8968442 7.270713 350
9 349.27987 36.048584 42.525923 51.11470 6.2927509 8.067794 400
10 398.82577 42.673436 50.544156 51.05616 6.9932463 8.627020 450
11 452.44586 50.089907 59.334299 53.86205 7.4026165 9.161075 500
12 503.59568 58.059554 68.386690 51.20446 8.1052583 9.596591 550
13 557.14943 66.213398 77.638497 52.96838 8.5918977 10.660603 600
14 610.77343 75.284911 88.633152 54.93132 9.1269278 11.101193 650
15 665.84134 84.955259 100.304303 55.50109 9.4717120 11.802664 700
16 720.21461 95.758498 112.027161 53.62790 10.1322070 12.393890 750
17 772.87859 106.627493 124.581833 50.75567 10.6291880 13.124825 800
18 824.82842 118.511719 137.337678 51.92641 11.0529974 13.799954 850
19 876.22800 130.054478 150.804360 51.00933 11.6053936 14.023371 900
20 926.42952 142.073144 164.977391 48.61321 12.0163249 15.000552 950
21 973.50125 154.830550 179.832186 46.47075 12.6120386 15.153725 1000
The blue line represents the empirical network K-function of the Grab ride hailing origin points in Changi planning area. The gray envelop represents the results of the 50 simulations in the interval 2.5% - 97.5%. Because the blue line is above the gray area, we can infer that these origin points in Changi planning area are in clusters, which reinforces our observations made above.
kfun_tp <- kfunctions(tp_roads,
tp_origin[c("trj_id","PLN_AREA_N", "geometry")],
start = 0,
# A double, the start value for evaluating the k and g functions.
end = 1000,
# A double, the last value for evaluating the k and g functions.
step = 50,
# A double, the jump between two evaluations of the k and g function
width = 50,
# The width of each donut for the g-function
nsim = 50,
# number of Monte Carlo simulations required.
resolution = 50,
verbose = FALSE,
agg = 10,
conf_int = 0.05
# A double indicating the width confidence interval (default = 0.05).
)
kfun_tp$plotk

$plotg

$values
obs_k lower_k upper_k obs_g lower_g upper_g distances
1 0.000000 0.000000 0.000000 3.063765 0.4421406 0.6130435 0
2 9.342307 1.377242 1.734585 13.672235 1.7075773 2.0817633 50
3 24.414290 3.410073 3.924959 15.902540 2.1587204 2.7264608 100
4 41.077689 5.861521 6.959249 16.683727 2.6969848 3.4020865 150
5 57.738184 8.816239 10.485047 16.776657 3.1041316 3.8732674 200
6 75.147922 12.154872 14.685310 18.022491 3.6798582 4.7036786 250
7 93.338848 16.296618 19.345138 18.347744 4.3864119 5.4137171 300
8 111.825986 21.052715 25.099644 19.419336 5.0016334 6.1119942 350
9 132.000374 26.388894 31.651311 20.456079 5.7800621 7.0282198 400
10 152.970469 32.626633 39.031791 21.155954 6.6395137 7.9580944 450
11 173.673392 39.640914 47.345050 21.321484 7.3499878 9.1642887 500
12 195.654094 47.562853 56.535620 22.785122 8.2352853 10.0699145 550
13 219.049065 56.639730 67.236874 23.243961 9.1369907 11.2673967 600
14 243.294920 66.362757 78.791625 24.861513 9.9935382 12.0599100 650
15 268.870827 76.838076 91.276687 26.275782 10.8467461 13.1133517 700
16 295.985877 88.061912 105.079023 27.748132 11.7536787 14.4680878 750
17 324.674919 100.112964 119.542755 29.891315 12.5255734 15.1376149 800
18 355.382270 113.085615 135.042940 32.104196 13.5755301 16.3342258 850
19 388.200861 127.467598 152.019394 32.632732 14.4512443 17.6732801 900
20 421.193694 142.679556 170.017347 34.090562 15.4589473 18.5044172 950
21 456.100292 158.526484 188.698330 35.591952 16.4466123 19.8219816 1000
Similar to Changi planning area, as the blue line is above the grey area, we can infer that the Tampines planning area consists of mainly origin points in clusters.
kfun_wl <- kfunctions(wl_roads,
wl_origin[c("trj_id","PLN_AREA_N", "geometry")],
start = 0,
# A double, the start value for evaluating the k and g functions.
end = 1000,
# A double, the last value for evaluating the k and g functions.
step = 50,
# A double, the jump between two evaluations of the k and g function
width = 50,
# The width of each donut for the g-function
nsim = 50,
# number of Monte Carlo simulations required.
resolution = 50,
verbose = FALSE,
agg = 5,
conf_int = 0.05
# A double indicating the width confidence interval (default = 0.05).
)
kfun_wl$plotk

$plotg

$values
obs_k lower_k upper_k obs_g lower_g upper_g distances
1 0.00000 0.000000 0.000000 12.79035 0.9525667 1.238177 0
2 30.72008 3.133496 3.759995 36.94501 3.9462620 4.893020 50
3 69.60787 7.720477 9.116881 41.21513 5.0740802 6.286219 100
4 111.78038 13.485549 15.836522 42.55706 6.2890234 7.791179 150
5 154.50168 20.493604 24.064728 42.34075 7.3815910 9.088440 200
6 198.64501 28.531937 33.807306 46.01402 9.0281534 10.902443 250
7 245.62842 38.409509 45.257535 46.06609 10.6510820 12.703226 300
8 291.74659 49.824487 58.637132 48.20917 12.0991597 15.071825 350
9 340.81299 62.740419 74.663726 49.31876 14.2348239 17.144198 400
10 391.33748 77.880341 93.320495 52.93195 16.1569818 19.799208 450
11 445.41507 95.196787 114.235103 53.94941 18.0268647 22.520913 500
12 501.55562 115.224122 137.637280 58.50394 20.7197283 24.838238 550
13 560.44011 137.307006 163.546454 58.34371 23.1446075 28.063064 600
14 619.75722 162.547220 192.208177 61.11969 25.4268821 30.737902 650
15 680.92097 189.478461 224.089320 62.37750 27.6486699 33.196029 700
16 745.74999 219.255985 258.263352 66.83590 30.3725781 36.154073 750
17 814.30034 250.842905 295.817634 71.84709 32.3007446 39.598215 800
18 890.13315 284.529839 336.506815 78.82910 35.4304350 41.818200 850
19 971.08530 321.563174 380.133810 82.05774 37.8663300 44.697331 900
20 1054.44490 360.838726 426.995446 86.54017 39.7438238 47.758123 950
21 1146.03231 401.979153 476.277756 95.30875 42.8362608 50.723377 1000
Similar to Changi planning area, as the blue line is above the grey area, we can infer that the Woodlands planning area consists of mainly origin points in clusters.
kfun_nv <- kfunctions(nv_roads,
nv_origin[c("trj_id","PLN_AREA_N", "geometry")],
start = 0,
# A double, the start value for evaluating the k and g functions.
end = 1000,
# A double, the last value for evaluating the k and g functions.
step = 50,
# A double, the jump between two evaluations of the k and g function
width = 50,
# The width of each donut for the g-function
nsim = 50,
# number of Monte Carlo simulations required.
resolution = 50,
verbose = FALSE,
agg = 5,
conf_int = 0.05
# A double indicating the width confidence interval (default = 0.05).
)
kfun_nv$plotk

$plotg

$values
obs_k lower_k upper_k obs_g lower_g upper_g distances
1 0.000000 0.0000000 0.0000000 1.891585 0.07522092 0.1543135 0
2 3.964585 0.2443574 0.3716798 4.179186 0.29601645 0.4935820 50
3 8.256602 0.6023205 0.8652618 4.486707 0.40464431 0.6110594 100
4 12.528708 1.0773185 1.5294183 4.053080 0.51924560 0.7816339 150
5 16.840637 1.7247715 2.3067381 4.433610 0.64701055 1.0151506 200
6 21.367167 2.4685737 3.3649195 4.924758 0.80088158 1.1827384 250
7 26.568472 3.3707823 4.5403570 5.110598 0.94656681 1.3893747 300
8 31.769778 4.4435653 6.1309476 5.546437 1.21636656 1.7965632 350
9 37.727717 5.7745332 8.0198777 6.449088 1.37023759 1.9566289 400
10 44.433441 7.2499695 9.9682102 6.807493 1.48096721 2.1954554 450
11 51.333855 8.9996302 12.2996163 6.869440 1.70651936 2.3676891 500
12 58.046216 10.7695343 14.8206234 6.413690 1.84811168 2.5628211 550
13 64.479817 12.7477339 17.3627587 6.834042 2.05928336 2.7619353 600
14 71.767397 14.9341185 20.2344280 7.670322 2.22476939 3.0195669 650
15 79.572674 17.2410778 23.3733528 7.814126 2.48383909 3.1988803 700
16 87.760692 19.9472611 26.7013256 8.767662 2.65142688 3.5451178 750
17 96.636761 22.7655014 30.1238775 9.196864 2.79180240 3.7395860 800
18 105.981854 25.7293164 33.7418932 8.993325 2.91447887 3.8264219 850
19 115.021639 28.6702332 37.7568099 9.289784 3.02731025 4.1271950 900
20 124.893279 31.6833842 41.8209521 9.953498 3.22155722 4.1941195 950
21 134.570229 35.0474187 45.9883018 9.840667 3.40219805 4.3766409 1000
Similar to Changi planning area, as the blue line is above the grey area, we can infer that the Novena planning area consists of mainly origin points in clusters.
The results of our G- and K-Function Analysis on all four planning area shows a spatial pattern of clustering among the grab origin points, which supports the idea that grab rides are commonly booked at the same location within an area, possibly due to designated pickup points or taxi stands.
In conclusion, our analysis of Grab ride-hailing origin points in the specific planning areas of Changi, Tampines, Woodlands, and Novena, and also the whole of Singapore uncovered noteworthy spatial patterns. The observed clustering of origin points within these areas suggests a localized preference for specific pickup locations, potentially driven by factors such as designated pickup points, popular landmarks, transportation hubs, or simply area with higher population density.
These findings hold practical implications for both Grab and urban planners as the identified clusters can guide Grab in optimizing their service by strategically placing vehicles or promoting the use of specific pickup points, ultimately enhancing the efficiency and user experience. Urban planners, on the other hand, can leverage this information to make informed decisions regarding infrastructure development, such as improving the accessibility of popular pickup locations or adjusting traffic flow in areas with high ride-hailing activity.
Moreover, understanding the spatial dynamics of Grab ride-hailing services contributes to a broader perspective on urban mobility patterns. This knowledge can be valuable for city officials, transportation authorities, and policymakers in crafting policies that support sustainable and efficient transportation solutions. By aligning urban planning efforts with the observed ride-hailing patterns, cities can work towards creating more resilient, user-friendly, and accessible transportation systems.
In essence, our analysis not only sheds light on the localized behaviors of Grab users but also opens avenues for strategic decision-making that can enhance the overall urban mobility landscape. As technology continues to shape the future of transportation, such spatial insights play a crucial role in fostering innovation and creating urban environments that are responsive to the evolving needs of their residents.